<?php
/**
 * 作用: 实例化配置参数
 * @author liwei
 */
namespace Minicli;

class Config
{
    protected $config = array();

    // 扫描 config 文件夹，加入到配置的大数组当中
    public function __construct()
    {
        foreach (glob(FRAME_BASE_PATH.'/config/*.php') as $file){
            $key = str_replace('.php','',basename($file));
            $this->config[$key] = require $file;
        }
    }

    // 获取配置值
    public function get($key)
    {
        $keys = explode('.', $key);
        $config = $this->config;

        foreach ($keys as $key) {
            $config = $config[$key];
        }

        return $config;
    }

    // 重置配置的值
    public function set($key, $val)
    {
        $keys = explode('.', $key);

        $newconfig = &$this->config;
        
        foreach ($keys as $key) {
            $newconfig = &$newconfig[$key]; // 传地址
        }

        $newconfig = $val;
    }
}
